<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="en">
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=9">
        <link rel="stylesheet" href="<%=basePath %>client/css/cssreset.css">
        <link rel="stylesheet" href="<%=basePath %>client/css/dailiyifen.css">
        <link rel="stylesheet" href="<%=basePath %>css/daohang.css">
        <script src="<%=basePath %>client/jss/jquery-1.11.1.min.js"></script>
        <script src="<%=basePath %>client/jss/menu.js"></script>
        <script src="<%=basePath %>client/jss/jquery.table2excel.js"></script>
        <style type="text/css">
        	.daohan>span{
        		display: none;
        	}
        	body{
        	font-family:"微软雅黑";
        	}
        	.psxa{
			color:#708dac;
			width:100%;
			line-height:23px;
			text-align: center;
			margin-top:27px;
			font-family: '微软雅黑';
			cursor:pointer;
			font-size:16px;
			}
		.ims{
			position:relative;
			top:4px;
			right:22px;
		}
        </style>
        
        <style type="text/css">
		   	#pageaaa a{
			        width: 23px;
			        height: 23px;
			        border: 1px solid #dce0e0;
			        text-align: center;
			        margin: 0 4px;
			        cursor: pointer;
			        display: inline-block;
			        font-size: 17px;
			    }
			    .current{
			        background-color: #5ac3e7;
			    }
			    a{
		         text-decoration:none;
		         color:#708dac;
		         }
		  </style>
         <script>
		  	function selectCheck(){
	    	   var judge = $("#selectCheck").val();
	    	   var objs = document.getElementsByName("items");
			   if(judge == 1){
				   for(var i = 0,l = objs.length;i < l;i++){
		    		   objs[i].checked = true;
		    	   }
				   $("#selectCheck").val(0);
	    	   }else{
	    		   for(var i = 0,l = objs.length;i < l;i++){
		    		   objs[i].checked = false;
		    	   }
	    		   $("#selectCheck").val(1);
	    	   }
	    	   
	    	   checkedShow();
	       }
		  	
		  	function checkedShow(){
		  		var str = "";
	    	    var number = 0;
	    	    var obj = document.getElementsByName("items");
				for(var i = 0,l = obj.length;i < l;i++){
					if(obj[i].checked){
						str += obj[i].value+",";
						number++;
					}
				}    	   
	    			
	    	    if(str == ""){
	    	    	$('.xiang').css('display', 'none');
	    		    $('.ganaa').css('display', 'none');
	    		    $('.shangchu').css('display', 'none');
	    		    $('.fenpeijuese').css('display', 'none');
	    		    $('.shangchus').css('display', 'none');
	    		  
	    	    }else{
	    		   $(".client_id").html(str);
	    		   $("#number").html(number);
	    		   $('.xiang').css('display', 'inline');
	    		   $('.ganaa').css('display', 'inline');
	    		   $('.shangchu').css('display', 'inline');
	    		   $('.shangchus').css('display', 'inline');
	    		   $('.fenpeijuese').css('display', 'inline');
	    		  
	    	   }
		  	}
		  </script>
    </head>
    <body>
    	<div class="headerx">
    		<p class="pa">客户管理系统CRM</p>
    		<p class="rights">
	    		<img src="<%=basePath %>client/images/user.png" alt="">
	    		${staff.staff_name}
	    		<button onclick="ind()"></button>
    		</p>
    	</div>
    	<section>
    		<ol class="lefts">
    			<li class="pb">
    				<img src="<%=basePath %>images/Users and permissions.png" alt="">
    				用户和权限
    				<img src="<%=basePath %>images/button (2).png" alt="">
    				<div class="div1">
    					<p class="zcd" id="zcd1"><a href="<%=basePath %>role/page.action">角色管理</a></p>
						<p class="zcd" id="zcd2"><a href="<%=basePath %>staff/selectTree.action">部门/用户管理</a></p>
    				</div>
    			</li>
    			<li class="px">
    				<img src="<%=basePath %>images/canshu.png" alt="">
    				业务参数和设定
    				<img src="<%=basePath %>images/button (2).png" alt="">
    				<div class="div1">
    					<%-- <p class="zcd" id="zcd1" name="ppa"><a href="<%=basePath %>tradeManage/select.action">行业管理</a></p>
                        <p class="zcd" id="zcd2" name="ppa"><a href="<%=basePath %>compactGenre/select.action">合同类型</a></p>
                        <p class="zcd" id="zcd1" name="ppa"><a href="<%=basePath %>rank/select.action">客户级别</a></p>
                        <p class="zcd" id="zcd2" name="ppa"><a href="<%=basePath %>salestage/select.action">来源渠道</a></p>--%>
                        <p class="zcd" id="zcd2" name="ppa"><a href="<%=basePath %>rank/select.action">申请性质</a></p> 
                        <p class="zcd" id="zcd2" name="ppa"><a href="<%=basePath %>salestage/select.action">产品类别</a></p>
                        <p class="zcd" id="zcd2" name="ppa"><a href="<%=basePath %>salestage/select.action">来源渠道</a></p>
    				</div>
    			</li>
                <li class="py">
                    <img src="<%=basePath %>images/liucheng.png" />
                    	流程管理
                    <img src="<%=basePath %>images/button (2).png" />
                    <div class="div1">
                        <p class="zcd" id="zcd1"><a href="<%=basePath %>approveRole/select.action">审批流程管理</a></p>
                        <p class="zcd" id="zcd1"><a href="<%=basePath%>approve/count.action?pageSize=2" >已审批流程查看</a></p>
                    </div>
                </li>
                <li class="pxa">
                    <img src="../images/gonggao.png" alt="" width="18px">
                    <a href="../notice/page.action" style="color:#708dac;text-decoration: none;">公告管理&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                </li>
                <li class="pxaa">
                    <img src="../images/kehu (1).png" alt="">
                    资源开发
                    <img src="../images/button (2).png" alt="">
                    <div class="div1" style="display:block;">
                        <p class="zcd" id="zcd1"><a href="<%=basePath %>client/weifencount.action?zhuizong=0">用户开发</a></p>
                        <p class="zcd" id="zcd2"><a href="../client/findByAllForAgent.action?start=1" style="color:#fff;">代理开发</a></p>
                    </div>
                </li> 
               <%--  <li class="pxas">
    				<img src="../images/kehuzilao.png" alt="">
    				客户资料
    				<img src="../images/button (2).png" alt="">
    				<div class="div1" >
    					<p class="zcd" id="zcd1"><a href="<%=basePath%>client/findByAllData.action?start=1">用户资料</a></p>
						<p class="zcd" id="zcd2"><a href="<%=basePath%>client/findByAllData.action">代理资料</a></p>
    				</div>
    			</li> --%>
    			<li class="psxa">
    				<img src="../images/operation-management.png" alt="" width="16px" class="ims">
    				<a href="<%=basePath %>Operate/count1.action">运营管理&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
    			</li>
    		</ol>
    		<div class="righta">
    			<div class="smalls">
    				<ul>
		    			<li name="oli">
		    				<p class="hangye">代理开发</p>
		    				<div class="fen">
		    					<div class="headers">
		    						<p class="headersa"><a href="<%=basePath %>client/findByAllForAgent.action?start=0" style="color:#000;">未开发</a></p>
		    						<p class="headersa"><a href="<%=basePath %>client/findByAllForAgent.action?start=1" style="color:#000;">正在追踪</a></p>
		    						<p class="headersa"><a href="<%=basePath %>client/findByAllForAgent.action?start=2" style="color:#000;">已开发</a></p>
		    						<p class="headersb"><a href="<%=basePath %>client/findByAllForAgent.action?start=3" style="color:#fff;">回收站</a></p>
		    					</div>
		    				</div>
		    				<p class="daohan">
		    					<input type="text" id="select" value="${select}" placeholder="公司负责人" style="vertical-align:middle;">
	    						<button onclick="selectClient()" class="butsss" style="vertical-align:middle;">搜索</button>
		    					<span class="xiang">已选中<span id="number"></span>项</span> 
		    					<span class="ganaa">|</span>
		    					<span onclick="deleteClient()" class="shangchu">删除</span>
		    					<span class="fenpeijuese">重新分配跟踪角色</span>
		    					<span class="shangchus" onclick="updatePage()">编辑</span>
		    				</p>
		    				<table>
		    					<thead>
		    						<tr class="trs">
		    							<td><input type="checkbox" class="check1" id="selectCheck" value="1" onclick="selectCheck()"></td>
		    							<td>编号</td>
		    							<td>公司负责人</td>
		    							<td>电话</td>
		    							<td>公司名称</td>
		    							<td>联系QQ</td>
		    							<td>分配的员工</td>
		    							<td>来源渠道</td>
		    							<td>追踪情况</td>
		    						</tr>
		    					</thead>
		    					<tbody id="all">
		    						<c:forEach items="${clients}" var="client">
		    							<tr>
			    							<td>
			    								<input type="checkbox" class="check1" value="${client.client_id}" name="items" onclick="checkedShow()">
			    							</td>
			    							<td><a style="text-decoration:none;color:#8c8c8d;font-size:14px;" href="../client/newrecord.action?id=${client.client_id}">${client.client_id}</a></td>
			    							<<td>${client.company_fuzeren}</td>
			    							<td>${client.client_phone}</td>
			    							<td>${client.company_name}</td>
			    							<td>${client.client_qq}</td>
			    							<td>
			    								<c:forEach items="${staffList}" var="staffList">
			    									<c:if test="${staffList.staff_id == client.client_staffId}">
			    										${staffList.staff_name}
			    									</c:if>
			    								</c:forEach>
			    							</td>
			    							<td>${client.client_record}</td>
			    							<td>${client.client_remarks}</td>
			    						</tr>
		    						</c:forEach>
		    					</tbody>
		    				</table>
		    			</li>
		    		</ul>
		    		<div id="pageaaa" style="text-align:right;margin-top:100px;width:98%;"></div>
    			</div>
    			
    		</div>    		
    	</section>
    	<div class="smallsa"></div>
    	<div class="divaa">
    		<p class="paa">&nbsp;&nbsp;&nbsp;&nbsp;分配客户<span class="guan"><img src="../images/guanbi.png" alt=""></span></p>
			<form action="javascript:updateStaffId()" method="post">
				<p>
                    	部门&nbsp;:
                    <select name="" id="depId" class="" onchange="findByStaff()">
                        <c:forEach items="${departments}" var="department">
                        	<option value="${department.department_id}">${department.department_name}</option>
                        </c:forEach>
                    </select>            
                </p>
                <p>人员&nbsp;:
                    <select name="" id="depStaff">
                        
                    </select>
                </p>
				<p class="paf"><input type="button" value="取消"><input type="submit" value="确定"></p>
			</form>
    	</div>
    	<div class="bianji">
    		<p>编辑资料<img src="../images/guanbi.png" alt="" class="gb"></p>
    		<form action="javascript:update()" method="post">
    			<p>公司负责人<input type="text" id="upclient_company_name" style="margin-left:20px;"><span>*</span></p>
    			<p>电话&nbsp;&nbsp;<input type="text" id="upclient_phone"><span>*</span></p>
    			<p>公司名称<input type="text" id="upclient_staff_name" style="margin-left:30px;"><span>*</span></p>
    			<p>联系QQ<input type="text" id="upclient_encode" style="margin-left:30px;"><span>*</span></p>
    			<p>分配的员工
    				<select>
    					<option>张三</option>
    					<option>张三</option>
    				</select>
    				<span style="font-size:20px;">*</span>
    			</p>
    			<p>来源渠道<input type="text" id="upclient_name" style="margin-left:30px;"><span>*</span></p>
    			<p>追踪情况<input type="text" id="upclient_remarks" style="margin-left:30px;"><span>*</span></p>
    			<p><input type="submit" value="确定"></p>
    		</form>
    	</div>
        <p class="client_id" style="display: none"></p>
        <div style="display: none">
        	<span class="pageCount">${pageCount}</span>
        	<span class="pageNum">${pageNum}</span>
    	</div>
    </body>
    <script>
    $('.shangchus').click(function(){
    	var lengths=$(".check1:checked").length;
    	if(lengths>1){
    		alert("只能编辑一项！");
    		return;
    	}if(lengths==1){
    		$('.bianji').css('display','block');
        	$('.smallsa').css('display','block');
    	}
    	
    })
    $('.gb').click(function(){
    	$('.bianji').css('display','none');
    	$('.smallsa').css('display','none');
    })
    function ind(){
    	window.location.href= "../notice/findByAll.action";
    }
    $('.paf>input:nth-of-type(1)').click(function(event) {
        $('.divaa').css('display', 'none');
        $('.smallsa').css('display', 'none');
    });
    $(".imgx").click(function(){

		if($(".dia").css("display")=="none"){

		$(".dia").show();

		}else{

		$(".dia").hide();

		}

		});
    var usern=document.getElementById('usernames');
    var jb=document.getElementById('jibie');
    var pho=document.getElementById('photo');
    function texts(){
        var val=true;
        var pat=/\s/;
        var use=usern.value;
        var pst=/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        var jie=jb.value;
        var phots=pho.value;
        if(use==''||pat.test(use)){
            alert("请输入名称！");
            val=val&&false;
        }else if(phots==''||!pst.test(phots)||pat.test(phots)){
            alert("请输入电话号码或正确格式的号码！");
            val=val&&false;
        }
        return val;
    }
     $(function() {
            $(".daochu").click(function(){
                $("table").table2excel({
                    exclude: ".noExl",
                    name: "Excel Document Name",
                    filename: "myFileName",
                    exclude_img: true,
                    exclude_links: true,
                    exclude_inputs: true
                });
            });
            
        });
    $('.updateTop').click(function(event) {
            $('.dao').css('display', 'block');
            $('.smallsa').css('display', 'block');
        });
        $('.dao>p>img').click(function(event) {
            $('.dao').css('display', 'none');
            $('.smallsa').css('display', 'none');
        });
        $('.buts').click(function(event) {
            $('.dao').css('display', 'none');
            $('.smallsa').css('display', 'none');
        });
    	$('.daohan>span:nth-of-type(4)').click(function(event) {
    		$('.divaa').css('display', 'block');
    		$('.smallsa').css('display', 'block');
    	});
    	$('.guan').click(function(event) {
    		$('.divaa').css('display', 'none');
    		$('.smallsa').css('display', 'none');
    	});
    	/* $('.imgd').click(function(event) {
    		$('.xinjian').css('display', 'block');
    		$('.smallsa').css('display', 'block');
    	}); */
    	$('.xinjian>p>img').click(function(event) {
    		$('.xinjian').css('display', 'none');
    		$('.smallsa').css('display', 'none');
    	});
    	
    	function deleteClient(){
    		var client_id = $(".client_id").html();
    		client_id = client_id.substring(0,client_id.length-1);
    		$.ajax({
				type:"post",
				url:"<%=basePath %>client/deleteByClients.action",
				data:"ids="+client_id,
				success:function(data){
					alert(data);
					if(data == "删除成功"){
						location.href= "<%=basePath%>/client/findByAllForAgent.action?start=1";
					}
				},
				error:function(e){
				}

	   		 });
    	}
    	function selectBy(){
    		var vals = $("#selectBy").val();
    		if(vals == ""){
    			return false;
    		}
    	}
    	function selectClient(){
    		var select = $("#select").val();
    		location.href="../client/findByAllForAgent.action?select="+select+"&start=3";
    	}
    	
    	function saveClient(){
    		var name = $("#client_name").val();
    		var phone = $("#client_phone").val();
    		var company_name = $("#client_company_name").val();
    		var client_encode = $("#client_encode").val();
    		var client_ratio = $("#client_ratio").val();
    		var client_staff_name = $("#client_staff_name").val();
    		var client_remarks = $("#client_remarks").val();
    		var numbers=/^[0-9]*$/;
    		if(!numbers.test(client_ratio)){
    			alert("返佣比例只能是数字！");
    			return;
    		}
    		$.ajax({
				type:"post",
				url:"<%=basePath %>client/save.action",
				data:"client_name="+name+"&client_phone="+phone+"&company_name="+company_name+"&client_encode="+client_encode+"&client_ratio="+client_ratio+"&staff_name="+client_staff_name+"&client_remarks="+client_remarks,
				success:function(data){
					alert(data);
					if(data == "新增成功"){
						location.href= "<%=basePath%>/client/findByAllForAgent.action?start=1";
					}
				},
				error:function(e){
				}

	   		 });
    	}	
    	function updateTop(){
    		$('.dao').css('display', 'block');
            $('.smallsa').css('display', 'block');
    	}
    	
    	function findByStaff(){
     	   var depId = $("#depId option:selected").val();
     	   $.ajax({
  				type:"post",
  				data:"id="+depId,
  				url:"<%=basePath %>staff/findByDepId.action",
  				success:function(data){
 					var jsons = eval("("+data+")");
 					$("#depStaff").html("");
 					var staff2 = "<option value='0'>请选择员工</option>";
 					$("#depStaff").append(staff2);
 					for(var i =0,l = jsons.length;i < l;i++){
 						var aaaa = "<option value='"+jsons[i].staff_id+"'>"+jsons[i].staff_name+"</option>"
 						$("#depStaff").append(aaaa);
 					}
 				},
 				error:function(e){
 					alert("发生未知错误请刷新页面");
 				}

	   		 });

        }
    	
    	 function updateStaffId(){
	    	   var client_id = $(".client_id").html();
	    	   client_id = client_id.substring(0,client_id.length);
	      	   var depId = $("#depId").val();
	      	 /*   var depIds = $("#depIds").val(); */
	      	   var depStaff = $("#depStaff option:selected").val();
	      	   $.ajax({
	   				type:"post",
	   				data:"client_id="+client_id+"&depId="+depId+"&staff_id="+depStaff+"&select=0",
	   				url:"<%=basePath %>client/updateByPer.action",
	   				success:function(data){
	  					alert(data);
	  					location.href="<%=basePath %>client/findByAllForAgent.action?start=3";
	  				},
	  				error:function(e){
	  					alert(e);
	  					alert("请选择部门");
	  				}

	 	   		 });

	         } 
    	function exportClient(){
	  		
    		 //var client_id = $(".client_id").html();
		  		
		  		var client_id =${pageNum};
		  		/* if(client_id.length>0){
		  			client_id = client_id.substring(0,client_id.length-1);
		  		}else{
		  			client_id = null;
		  		} */
		  		
		  		location.href="../client/exportClient.action?start=3&id="+client_id;
	  		
	  	 }
    	 
    	 function updatePage(){
		  		var client_id = $(".client_id").html();
		  		if(client_id == ""){
		  			return;
		  		}
	    	    
		  		client_id = client_id.substring(0,client_id.length-1);
		  		var b = client_id.split(",")
	    	    if(b.length > 1){
	    		   return;
	    	    }
		  		var depStaff = $("#depStaff option:selected").val();
		      	   $.ajax({
		   				type:"post",
		   				data:"client_id="+client_id,
		   				url:"<%=basePath %>client/findById.action",
		   				success:function(data){
		   					var json = eval("("+data+")");
		   					$("#upclient_name").val(json[0].client_name);
		   					$("#upclient_phone").val(json[0].client_phone);
		   					$("#upclient_company_name").val(json[0].company_name);
		   					$("#upclient_encode").val(json[0].client_encode);
		   					$("#upclient_ratio").val(json[0].client_ratio);
		   					$("#upclient_staff_name").val(json[0].staff_name);
		   					$("#upclient_remarks").val(json[0].client_remarks);
		  				},
		  				error:function(e){
		  					alert("发生未知错误请刷新页面");
		  				}
	 	   		 });
		  		
		  	}
		  	 function update(){
		    	   var client_id = $(".client_id").html();

		    	   if(client_id == ""){
		    		   return;
		    	   }
		    	   client_id = client_id.substring(0,client_id.length-1);
		    	   var b = client_id.split(",")
		    	   if(b.length > 1){
		    		   return;
		    	   }
		    	   var upclient_name = $("#upclient_name").val();
		    	   var upclient_phone = $("#upclient_phone").val();
		    	   var upclient_company_name = $("#upclient_company_name").val();
		    	   var upclient_encode = $("#upclient_encode").val();
		    	   var upclient_ratio = $("#upclient_ratio").val();
		    	   var upclient_staff_name = $("#upclient_staff_name").val();
		    	   var upclient_remarks = $("#upclient_remarks").val();
		    	   var numbers=/^[0-9]*$/;
		    	   if(!numbers.test(upclient_ratio)){
		   			alert("返佣比例只能是数字！");
		   			return;
		   			}
		      	   $.ajax({
		   				type:"post",
		   				data:"client_id="+client_id+"&client_name="+upclient_name+"&client_phone="+upclient_phone+"&company_name="+upclient_company_name+"&client_encode="+upclient_encode+"&client_ratio="+upclient_ratio+"&staff_name="+upclient_staff_name+"&client_remarks="+upclient_remarks,
		   				url:"<%=basePath %>client/updateById.action",
		   				success:function(data){
		  					alert(data);
		  					location.href="<%=basePath%>client/findByAllForAgent.action?start=1";
		  				},
		  				error:function(e){
		  					alert("发生未知错误请刷新页面");
		  					
		  				}

		 	   		 });

		         } 
    	
    </script>
    <script src="../client/js/paging4.js"></script>
   	<script type="text/javascript">
	    $(function(){
	    	var pageCount = $(".pageCount").html();
	    	var pageNum = $(".pageNum").html();
	    	pageNum = parseInt(pageNum);
	    	pageCount = parseInt(pageCount);
	        $('#pageaaa').paging({pageNo:pageNum,totalPage:pageCount,callback:function(cur){
	            console.log(cur);
	        }});
	    });
    </script>
</html>